package cn.mw.cmdb.param;

import cn.mw.components.mongodb.entity.SearchParam;
import cn.mw.components.mongodb.entity.SubCondition;
import lombok.Data;

import java.util.List;
import java.util.Map;

import static cn.mw.cmdb.enums.ZabbixAssetsStatusEnum.ALERT;
import static cn.mw.cmdb.enums.ZabbixAssetsStatusEnum.NORMAL;
import static cn.mw.cmdb.service.impl.TableViewManageServiceImpl.itemAssetsStatusKey;
import static cn.mw.cmdb.util.ValConvertUtil.strValueConvert;
import static cn.mw.components.mongodb.entity.CriteriaOpsType.like;

@Data
public class InstanceTrendSearchParam extends SearchParam implements SearchParamConvert {
    //维度统计条件
    private String calcDimension;

    //时间线显示字段
    private List<String> dateLineKeys;

    private List<String> filterDate;

    @Override
    public void convert() {
        if (getCondition() != null) {
            Map<String, SubCondition> map = getCondition();
            map.forEach((k, v) -> {
                String key = k;
                SubCondition subCondition = v;
                Object value = subCondition.getValue();
                String operation = subCondition.getOperation();
                //特殊处理，前端查询资产状态：告警时，默认设置为正常，从正常状态中细分出告警
                if (itemAssetsStatusKey.equals(key) && like.name().equals(operation) && ALERT.getName().contains(strValueConvert(value))) {
                    subCondition.setValue(NORMAL.getName());
                }
            });
        }
    }
}
